package com.edward.service;


import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.edward.PagerModel;
import com.edward.model.CommercialList;


public class CommercialListManager extends HibernateDaoSupport {

	public void addCommercialList(CommercialList commercialList) {
		
		getHibernateTemplate().save(commercialList);
	}
	
	public void updateCommercialList(CommercialList commercialList) {
		
		getHibernateTemplate().update(commercialList);
	}
	
	public void deleteCommercialList(int id){
		
		getHibernateTemplate().delete(getCommercialList(id));
	}
	
	public CommercialList getCommercialList(int id){
		CommercialList d =(CommercialList)getHibernateTemplate().get(CommercialList.class, id);
		return d;
	}
	

	@SuppressWarnings("unchecked")
	public List<CommercialList> listCommercialList() {
		return getHibernateTemplate().find("from CommercialList");
	}

	
	@SuppressWarnings("unchecked")	
	public PagerModel pagerList(int start,int limit) {
		List <CommercialList>list = getHibernateTemplate().find("from CommercialList" );
		int total = list.size();
		int toIndex = start + limit;
		if(toIndex>total){
			toIndex =  total;
		}
		List <CommercialList>datas = list.subList(start, toIndex);
		PagerModel pm = new PagerModel();
		pm.setTotal(total);
		pm.setDatas(datas);
		return pm;
		
	}
	


}



